package com.example.pipeline.controller;

import com.common.pattern.pipeline.Result;
import com.common.pattern.pipeline.bo.BusinessContext;
import com.common.pattern.pipeline.config.PipelineManualProperty;
import com.common.pattern.pipeline.service.ExecutorService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;

/**
 * @title: PipelineController
 * @Author xu-xiang
 * @Date: 2023/8/11 9:42
 * @description:
 */
@Slf4j
@RestController
public class PipelineController {

    @Resource
    private PipelineManualProperty pipelineManualProperty;

    @Resource
    private ExecutorService executorService;

    @RequestMapping("/config")
    public Result<Object> config() {
        return Result.ok(pipelineManualProperty);
    }

    @RequestMapping("/route")
    public Result<Object> route() {
        BusinessContext pipelineContext = new BusinessContext();
        pipelineContext.setModelId(1L);
        HashMap<String, Object> inputParams = new HashMap<>(2);
        pipelineContext.setInputParams(inputParams);

        inputParams.put("expirationDate", "2023-8-10 11:45:43");
        inputParams.put("factory", "fa♂Q工厂");
        inputParams.put("permittedProduction", "准许生产");
        inputParams.put("QS", "质量安全");
        Result<String> stringResult = executorService.dealSync(pipelineContext);
        System.err.println(stringResult);
        return Result.ok(pipelineManualProperty);
    }

}
